<script type="text/javascript">
$(function () {
	var pg = App.sequence.segmentEdit.ui, pp = pg.params,
		numberName = pg.children('.navi').seek('title');

	var frm= {
		begin:pg.seek('begin'),
		end:pg.seek('end'),
		current:pg.seek('current'),
		endMsg:pg.seek('endMsg')
	};
	function setValues(o){
		pg.params.id=o.id;
		frm.begin.val(o.beginNo);
		frm.end.val(o.endNo);
		frm.current.val(o.currentNo);
	}
	function getValues(){
		return {
			id: pg.params.id,
			begin: parseInt(frm.begin.val()),
			end: parseInt(frm.end.val()),
			current: parseInt(frm.current.val())
		};
	}

	//验证方法
	function validate1(p){
		var x2 = App.validate2, v = App.sequence.validator, m = pg.find('.msg').html('');
		var vd = true
			&& x2(v.svc.numberBig, frm.begin)
			&& x2(v.svc.numberBig, frm.end)
			&& x2(v.svc.numberBig, frm.current)
		return vd;
	}
	//比较
	function compare(b,c,e) {
		if(c<b) {
			return {
				resultStatus: false,
				resultInfo: '当前值应大于或等于开始值'
			};
		}
		if(c>e) {
			return {
				resultStatus: false,
				resultInfo: '当前值应小于或等于结束值'
			};
		}
		return {resultStatus:true}
	}
	
	setValues(pg.params);
	//失去焦点判断
	pg.find('input').blur(function(e){
		frm.endMsg.html('');
		var pms = getValues();
		if(!validate1(pms,e.currentTarget.name))
			return;
	});

	pg.seek('back').click(function(){
		App.show({
			title: '号段管理',
			ctx: 'sequence',
			action: 'infoIndex',
			params: {}
		}, $.noop, pg.parent());
	});


	//提交
	pg.seek('ok').click(function(){
		var pms = getValues();
		if(!validate1(pms))//触发验证
			return;
		
		var re= compare(pms.begin,pms.current,pms.end)
		if(re.resultStatus==false) {
			frm.endMsg.html(re.resultInfo);
			return;
		}else {
			frm.endMsg.html('');
		}
		
		var w = mac.wait('Loading...');
		$.post(App.ctx + '/segment/update.do', pms, function(rs){
			var ro = mac.eval(rs);
			if (ro.success) {
				/* App.show({
					ctx : 'sequence',
					action : 'segmentIndex',
					params : {}
				}, $.noop, pg.parent()); */
				pg.callback()
				w.close();
				pg.close();
				
			} else {
				w.close();
				pg.seek('msg').html(mac.msg(ro.data, ro.params));
			}
		});
		return false;
	});
	/* if (pg.params.id) {
		numberName.text(pp.title+'序列')
	} */



});
</script>
<div class="form">
	<div class="item">
		<span class="label">序列起始值：</span>
		<input class="input" min="1" type="number" name="begin" placeholder="请填入序列起始值" />
		<span class="msg"></span>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">序列结束值：</span>
		<input class="input" min="1" type="number" name="end" placeholder="请填入序列结束值" />
		<span class="msg"></span>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">序列当前值：</span>
		<input class="input" min="1" type="number" name="current" placeholder="请填入序列当前值" />
		<span class="msg"></span>
		<div class="clear"></div>
	</div>
	<div class="endMsg">
		<span class="msg " name="endMsg"></span>
	</div>
	<div class="bottom">
		<button name="ok" class="addBtn">提交</button>
	</div>
	
</div>